#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int left = 0, max = nums.size() - 1;
        int right = max-1;
        int count = 0;
        

        while (max >= right &&right>=0 &&max>0)
        {
           // while (left <= right)
            for(left=0,right=max-1;left<right;)
            {
                if (nums[left] + nums[right] > nums[max])
                {
                    count += right - left ;
                    right--;
                }
                else
                {
                    left++;
                }
            }
            
            max--;
            if (max == right)
            {
                right--;
            }
        }
        return count;
    }
};

int main()
{
    vector<int> v = { 24,3,82,22,35,84,19 };
    Solution s;
    s.triangleNumber(v);
    return 0;
}